@echo off & setlocal
REM $x = $MyInvocation.MyCommand.Definition
REM $x = Split-Path -Parent $MyInvocation.MyCommand.Definition
REM $env:GOPATH=$env:GOPATH+";F:\mp\cm2-demo"

set pkgName=win
set pkgFullName=cm2/terminal/console/win
set resource=terminal\console\win\
set appName=win-console

cd %~dp0
cd..
set gpath=%cd%
@echo building root set to %gpath%

REM 设置环境变量
set GOPATH=%GOPATH%;%gpath%
@echo GOPATH set to %GOPATH%

REM 编译
go install -v %pkgFullName%\main


REM 检查是否存在发布文件夹
set pkgRoot=%cd%\deploy\pkg
if not exist %pkgRoot% (
    md %pkgRoot%
)
set appRoot=%pkgRoot%\%appName%
if not exist %appRoot% (
    md %appRoot%
)

REM 剪切执行文件到 root 根目录
set buildExe=%cd%\bin\main.exe
xcopy /i /f /y %buildExe% %appRoot%\%appName%.exe
del /s /q %buildExe%

REM 复制所有其他资源文件
xcopy /s /e /i /f /y %cd%\resource\%resource%\* %appRoot%

endlocal